package com.wing.cabinet.controller.websocket;

import javax.websocket.ContainerProvider;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;

public class Client {

    public Session session;

    public void start(){
        WebSocketContainer webSocketContainer= ContainerProvider.getWebSocketContainer();
        String uri="ws://localhost:9306/websocket/cabOpen";
//        uri="ws://localhost:9302/websocket/onlineCount";
//        uri="ws://124.232.154.35:9306/websocket/cabOpen?cabCode";
        //uri="ws://146.56.196.8:9306/websocket/cabOpen";
        uri="ws://10.3.1.232:9306/websocket/cabOpen";

        try{
            session=webSocketContainer.connectToServer(CabinetClient.class, URI.create(uri));

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        Client client=new Client();
        client.start();
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
        try{
            String input="";
            do{
                input=bufferedReader.readLine();
                client.session.getBasicRemote().sendText(input);

            }while (!input.equals("quit"));
        }catch (Exception e){

        }


    }


}
